﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RM2012Server.Model;
using System.Data;
using RM2012Server.Business;
using DevComponents.DotNetBar.Controls;
using System.Windows.Forms;

namespace RM2012Server.Controller
{
    public class InvoiceCtrl
    {
        InvoiceDAO m_InvoiceDAO = new InvoiceDAO();

        public void LoadToComboBox(ComboBoxEx cmb)
        {
            cmb.DataSource = GetAll();
            cmb.DisplayMember = "InvoiceId";
            cmb.ValueMember = "InvoiceId";
        }

        public void LoadToDataGridViewComboBoxColumn(DataGridViewComboBoxColumn cmb)
        {
            cmb.DataSource = GetAll();
            cmb.DisplayMember = "InvoiceId";
            cmb.ValueMember = "InvoiceId";
            cmb.DataPropertyName = "InvoiceId";
            cmb.HeaderText = "Hóa đơn";
        }

        public void LoadToDataGridViewComboBoxExColumn(DataGridViewComboBoxExColumn cmb)
        {
            cmb.DataSource = GetAll();
            cmb.DisplayMember = "InvoiceId";
            cmb.ValueMember = "InvoiceId";
            cmb.DataPropertyName = "InvoiceId";
            cmb.HeaderText = "Hóa đơn";
        }

        public void LoadToDataGridView(DataGridViewX dgv)
        {
            dgv.DataSource = GetAll();
        }

        public void LoadToDataGridViewToday(DataGridViewX dgv)
        {
            dgv.DataSource = GetToday();
        }

        public void Show(DataGridViewX dgv, BindingNavigator bn)
        {
            BindingSource bs = new BindingSource();
            bs.DataSource = GetAll();
            bn.BindingSource = bs;
            dgv.DataSource = bs;
        }

        public void ShowWithSources(DataGridViewX dgv,
                         BindingNavigator bn,
                         TextBoxX txtAreaId,
                         TextBoxX txtAreaName,
                         TextBoxX txtRemark,
                         DataTable dtSources)
        {
            BindingSource bs = new BindingSource();
            bs.DataSource = dtSources;
        }

        public DataTable GetAll()
        {
            return m_InvoiceDAO.GetAll();
        }

        public DataTable GetAllFull()
        {
            return m_InvoiceDAO.GetAllFull();
        }

        public DataTable GetById(String invoiceId)
        {
            return m_InvoiceDAO.GetById(invoiceId);
        }

        public DataTable GetByIdForReport(String invoiceId)
        {
            return m_InvoiceDAO.GetByIdForReport(invoiceId);
        }

        public DataTable GetByLikeId(String invoiceId)
        {
            return m_InvoiceDAO.GetByLikeId(invoiceId);
        }

        public DataTable GetByCusId(String cusId)
        {
            return m_InvoiceDAO.GetByCusId(cusId);
        }

        public DataTable GetByTablesId(String tablesId)
        {
            return m_InvoiceDAO.GetByTablesId(tablesId);
        }

        public DataTable GetByIsPaid(bool isPaid)
        {
            return m_InvoiceDAO.GetByIsPaid(isPaid);
        }

        public DataTable GetByIsDeleted(bool isDeleted)
        {
            return m_InvoiceDAO.GetByIsDeleted(isDeleted);
        }

        public DataTable GetByYear(int year)
        {
            return m_InvoiceDAO.GetByYear(year);
        }

        public DataTable GetByMonth(int year, int month)
        {
            return m_InvoiceDAO.GetByMonth(year, month);
        }

        public DataTable GetByTotal(double min, double max)
        {
            return m_InvoiceDAO.GetByTotal(min, max);
        }

        public DataTable GetByDate(DateTime start, DateTime end)
        {
            return m_InvoiceDAO.GetByDate(start, end);
        }

        public DataTable GetByDateFull(DateTime dateChoise)
        {
            return m_InvoiceDAO.GetByDateFull(dateChoise);
        }

        public DataTable GetToday()
        {
            return m_InvoiceDAO.GetToday();
        }

        public int Add(InvoiceInfo info)
        {
            return m_InvoiceDAO.Add(info);
        }

        public int Update(InvoiceInfo info)
        {
            return m_InvoiceDAO.Update(info);
        }

        public int UpdateTotal(InvoiceInfo info)
        {
            return m_InvoiceDAO.UpdateTotal(info);
        }

        public int UpdatePaid(InvoiceInfo info)
        {
            return m_InvoiceDAO.UpdatePaid(info);
        }

        public int UpdateNeeded(InvoiceInfo info)
        {
            return m_InvoiceDAO.UpdateNeeded(info);
        }

        public int Delete(String invoiceId)
        {
            return m_InvoiceDAO.Delete(invoiceId);
        }

        public DataRow AddNewRow()
        {
            return m_InvoiceDAO.AddNewRow();
        }

        public void AddNewInvoice(DataRow m_Row)
        {
            m_InvoiceDAO.AddNewInvoice(m_Row);
        }

        public bool SaveData()
        {
            return m_InvoiceDAO.SaveData();
        }
    }
}
